﻿//for browser
var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
            && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
            && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
var is_nav4up = (is_nav && (isNaN(is_major) || is_major >= 4));
var is_nav6up = (is_nav && (isNaN(is_major) || is_major >= 5));
var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_nav4 = (is_nav && (isNaN(is_major) || is_major == 4));	
var is_ie4up  = (is_ie && (isNaN(is_major) || is_major >= 4));
var is_dhtml = (is_ie4up || is_nav4up)

//utilScript
function GetXPos(imgID) {
  if (is_ie4up || is_nav6up) return docjslib_getRealLeft(imgID)
  else return eval(imgID).x;
}

function GetYPos(imgID) {
  if (is_ie4up || is_nav6up) return docjslib_getRealTop(imgID)
  else return eval(imgID).y;
}

function docjslib_getRealLeft(imgElem) {
	xPos = eval(imgElem).offsetLeft;
	tempEl = eval(imgElem).offsetParent;
  	while (tempEl != null) {
  		xPos += tempEl.offsetLeft;
  		tempEl = tempEl.offsetParent;
  	}
	return xPos;
}

function docjslib_getRealTop(imgElem) {
	yPos = eval(imgElem).offsetTop;
	tempEl = eval(imgElem).offsetParent;
	while (tempEl != null) {
  		yPos += tempEl.offsetTop;
  		tempEl = tempEl.offsetParent;
  	}
	return yPos;
}


//for images
var rollOverImages = new Array();
var overIndicator = "_o";
var layers = new Array();
function createRollOver(img) {if (!rollOverImages[img.name] && document.images) rollOverImages[img.name] = new rollOver(img.src);}		
function imgOn(imgName) {if (document.images) if(rollOverImages[imgName]) document[imgName].src = rollOverImages[imgName].on.src;}
function imgOff() {if (document.images) for (var Image in rollOverImages) if(document[Image]) document[Image].src = rollOverImages[Image].off.src;}
function rollOver(on) {this.on = new Image();this.on.src = on.substring(0,on.lastIndexOf(".")) + overIndicator + on.substring(on.lastIndexOf("."),on.length);	this.off = new Image();this.off.src = on;}


function fToggleTags(objLayer,exConTagInBound,tagN){
    var exConStr = '';
	var arrToggleTags = new Array();
    if(exConTagInBound!='') exConStr=exConTagInBound;
    var arrTags = document.getElementsByTagName(tagN);
    for(var i=0;i<arrTags.length;i++)
 		if((exConStr!=''?eval('arrTags.item(i).'+exConStr):true) && fTagInBound(objLayer,arrTags.item(i))){
			if(document.arrExCon && document.arrExCon.length){
			   for(var j=0;document.arrExCon[j];j++) if(eval('arrTags.item(i).'+document.arrExCon[j])) arrToggleTags[arrToggleTags.length] = arrTags.item(i);}
			else arrToggleTags[arrToggleTags.length] = arrTags.item(i);
		}
	return arrToggleTags;
}
function fTagInBound(objLayer,aTag){
  with (objLayer.style){
  	var l = parseInt(left);
  	var t = parseInt(top);
  	var r = l+parseInt(width);
  	var b = t+parseInt(height);
	var ptLT = fGetXY(aTag);
	return !((ptLT.x>r)||(ptLT.x+aTag.offsetWidth<l)||(ptLT.y>b)||(ptLT.y+aTag.offsetHeight<t));
  }
}
function fGetXY(aTag){
  var oTmp = aTag;
  var pt = new Point(0,0);
  do {
  	pt.x += oTmp.offsetLeft;
  	pt.y += oTmp.offsetTop;
	if(!oTmp.offsetParent) return false; //for NS
  	oTmp = oTmp.offsetParent;
  } while(oTmp.tagName!="BODY");
  return pt;
}
function Point(iX, iY){
	this.x = iX;
	this.y = iY;
}


function iniPopUpLayer(){
	var d = document;
	if(!d.arrLayers) d.arrLayers = new Array();
	if(!d.arrExCon) d.arrExCon = new Array();
	for(var i=0;iniPopUpLayer.arguments[i];i++){
		d.arrLayers[iniPopUpLayer.arguments[i]] = iniPopUpLayer.arguments[++i];
		if(d.arrLayers[iniPopUpLayer.arguments[i-1]]!='') d.arrExCon[d.arrExCon.length] = iniPopUpLayer.arguments[i];
	}
}

function ClosePopup(id,cordX,cordY){ 
	if(is_dhtml){
	   var objDiv,styleDiv;
	   if(id){
		  (is_ie4up)? objDiv = document.all[id] : (is_nav6up) ? objDiv = document.getElementById(id) : objDiv = document.layers[id];
		  (is_ie4up || is_nav6up)? styleDiv = objDiv.style : styleDiv = objDiv;
		  //(is_ie4up)? cordX += document.body.scrollWidth/2 : cordX += window.innerWidth/2;
		  (is_ie4up || is_nav6up) ? styleDiv.visibility = "hidden" : styleDiv.visibility = "hide";
		  if(objDiv.arrToggleTags){
		     for(var i=0;objDiv.arrToggleTags[i];i++) objDiv.arrToggleTags[i].style.visibility = "visible";
		     objDiv.arrToggleTags.length=0;
		  }
		  imgOff();
	   }
	}
}

function OpenPopup(id,cordX,cordY){ 
	if(is_dhtml){
	   var objDiv,styleDiv;
	   if(id){
		  (is_ie4up)? objDiv = document.all[id] : (is_nav6up) ? objDiv = document.getElementById(id) : objDiv = document.layers[id];
		  (is_ie4up || is_nav6up)? styleDiv = objDiv.style : styleDiv = objDiv;
		  styleDiv.top = cordY + "px"; styleDiv.left = cordX + "px";
		  (is_ie4up || is_nav6up) ? styleDiv.visibility = "visible" : styleDiv.visibility = "show";
		  if(!objDiv.arrToggleTags) objDiv.arrToggleTags=new Array();
		  if(!objDiv.exCon) objDiv.exCon = '';
		  if(objDiv.arrToggleTags){
		     objDiv.arrToggleTags = fToggleTags(objDiv,objDiv.exCon,'select');
		     for(var i=0;objDiv.arrToggleTags[i];i++) objDiv.arrToggleTags[i].style.visibility = "hidden";
		  }
	   }
	}
}

function Popup(id,cordX,cordY){ 
	if(is_dhtml){
		var d=document,i,j,objDiv,styleDiv;
		imgOff();
		imgOn("menu_" + id);
		if(d.arrLayers) //if iniPopUpLayer()
		for (i in d.arrLayers){
			(is_ie4up)?objDiv = document.all[i]:(is_nav6up)?objDiv = document.getElementById(i):objDiv = document.layers[i];
			objDiv.exCon = d.arrLayers[i];
			if (id != i){
				(is_ie4up || is_nav6up) ? styleDiv = objDiv.style : styleDiv = objDiv;
				(is_ie4up || is_nav6up) ? styleDiv.visibility = "hidden" : styleDiv.visibility = "hide";
				if(objDiv.arrToggleTags){
				   for (j=0;objDiv.arrToggleTags[j];j++) objDiv.arrToggleTags[j].style.visibility = "visible";
				   objDiv.arrToggleTags.length=0;
				}
			}
		}
		
		if(id){
			(is_ie4up)? objDiv = document.all[id] : (is_nav6up) ? objDiv = document.getElementById(id) : objDiv = document.layers[id];
		    (is_ie4up || is_nav6up)? styleDiv = objDiv.style : styleDiv = objDiv;
			if(styleDiv.visibility == "visible" || styleDiv.visibility == "show")  ClosePopup(id,0,0);
			else OpenPopup(id,cordX,cordY)
		}
		else location.href=location.href;
	}
}
function Popup2(id,cordX,cordY){ 
	if(is_dhtml){
		var d=document,i,j,objDiv,styleDiv;
		imgOff();
		imgOn("menu_" + id);
		if(d.arrLayers) //if iniPopUpLayer()
		for (i in d.arrLayers){
			(is_ie4up)?objDiv = document.all[i]:(is_nav6up)?objDiv = document.getElementById(i):objDiv = document.layers[i];
			objDiv.exCon = d.arrLayers[i];
			if (id != i){
				(is_ie4up || is_nav6up) ? styleDiv = objDiv.style : styleDiv = objDiv;
				(is_ie4up || is_nav6up) ? styleDiv.visibility = "hidden" : styleDiv.visibility = "hide";
				if(objDiv.arrToggleTags){
				   for (j=0;objDiv.arrToggleTags[j];j++) objDiv.arrToggleTags[j].style.visibility = "visible";
				   objDiv.arrToggleTags.length=0;
				}
			}
		}
		
		if(id) OpenPopup(id,cordX,cordY)
		else location.href=location.href;
	}
}

function displayLayer(layerID,cordX,cordY,fPopupN){
	 imgOn('menu_'+layerID);
	 var layerX = cordX;
	 var layerY = cordY;
	 
	 var winWH = getWindowWH();
	 if(document.getElementById(layerID).offsetWidth + layerX>winWH.w)
	     layerX = winWH.w-document.getElementById(layerID).offsetWidth;
	 var scrollTop = document.documentElement.scrollTop||document.body.scrollTop,scrollLeft = document.documentElement.scrollLeft||document.body.scrollLeft;
	 if(document.getElementById(layerID).offsetHeight + layerY>winWH.h+scrollTop)
	     layerY = winWH.h+scrollTop-document.getElementById(layerID).offsetHeight;
	 if(layerY<scrollTop) layerY =scrollTop;
	 
	 if(!fPopupN) fPopupN = 'Popup';
	 eval(fPopupN+'(\''+layerID+'\','+layerX+','+layerY+')');
}

function getWindowWH(){
	var pointer = {w:0,h:0};
  	if(typeof(window.innerWidth)=='number'){//Non-IE
    	pointer.w = window.innerWidth;
    	pointer.h = window.innerHeight;
  	}
	else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)){//IE 6+ in 'standards compliant mode'
    	pointer.w = document.documentElement.clientWidth;
    	pointer.h = document.documentElement.clientHeight;
  	}
	else if(document.body&&(document.body.clientWidth||document.body.clientHeight)){//IE 4 compatible
    	pointer.w = document.body.clientWidth;
    	pointer.h = document.body.clientHeight;
  	}
	return pointer;
}